#pragma	once

namespace	Z
{

//------------------------------------------------------------------------------------------------------------------------
class CriticalSection
{
public:
    CriticalSection()	{
		::InitializeCriticalSection(&mCriticalSection);
	}
	~CriticalSection()	{
		::DeleteCriticalSection(&mCriticalSection);
	}
    void	enter()	{
		::EnterCriticalSection(&mCriticalSection);
    }
    void	leave()	{
		::LeaveCriticalSection(&mCriticalSection);
    }

private:
	CRITICAL_SECTION	mCriticalSection;

//------------------------------------------------------------------------------------------------------------------------
public:
	class	scoped_lock	{
	public:
		scoped_lock(CriticalSection& criticalSection)
			:	mCriticalSection(criticalSection)	{
			mCriticalSection.enter();
		}
		~scoped_lock()	{
			mCriticalSection.leave();
		}

	private:
		CriticalSection&	mCriticalSection;
	};
};

}